import 'whatwg-fetch'
import Config from '../config/Config'
// const ICT_DATA_SERVER = 'http://121.40.131.112:3000';
// const ICT_DATA_SERVER = 'https://mongo.ichangtou.com';

// const CHANNEL = 'search_baby'

/**
 * 发送事件
 * @param eventName, properties
 */
const track = function (eventName, properties = {}) {
  if (!(eventName instanceof String) && !(properties instanceof Object)) {
    console.warn('发送到统计数据', properties, '不是一个合法的对象, 忽略')
    return
  }

  // ict
  var trackData = Object.assign({}, {userId: '00'}, properties, {eventName})
  window.fetch(Config.getDataUrl() + '/event/book2', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(trackData)
  }).then(function (response) {
    return response.json()
  }).then(function (json) {
    // console.log('parsed json', json)
  }).catch(function (ex) {
    console.warn('ictdata parsing failed', ex)
  })
}

export {
  track
}
